<h2>DESCRIPTION</h2>

<em>r.colors</em> allows the user to create and/or modify the color
table for a raster map or several raster maps at once. 
The raster maps (specified on the command line
by <b>map</b> or as <b>file</b> using an input file with one map name per line) 
must exist in the user's current mapset search path.

<p>The <b>raster</b> option allows user to specify a raster map <i>name</i>
from which to copy the color map.

<p>The <b>raster_3d</b> option allows user to specify a 3D raster
map <i>name</i> from which to copy the color map.

<p>The <b>-e</b> flag equalizes the original raster's color table. It can
preclude the need for <em>grey.eq</em> rule, when used as
<b>-e color=</b><em>grey</em>. Note however, that this will not yield
a color table identical to <em>color=grey.eq</em>,
because <em>grey.eq</em> scales the fraction by 256 to get a grey
level, while <b>-e</b> uses it to interpolate the original color
table. If the original color table is a 0-255 grey scale, <b>-e</b>
is effectively scaling the fraction by 255. Different algorithms are
used. <b>-e</b> is designed to work with any color table, both the
floating point and the integer raster maps.

<p>The <b>-g</b> flag divides the raster's grey value range into 100
logarithmically equal steps (where &quot;step&quot; is a rule with the
same grey level for the start and end points). It can preclude the
need for <em>grey.log</em> rule, when used as <b>-g
color=</b><em>grey</em>. Note however, that this will not yield a
color table identical to <em>color=grey.log</em>. Different algorithms
are used. Unlike <b>color=</b><em>grey.log</em>, <b>-g</b> is designed
to work with both floating point and integer rasters, without
performance issues with large datasets, of any original color
table. Logarithmic scaling doesn't work on negative values. In the
case when the value range includes zero, there's no realistic
solution.

<p>The <b>-e</b> and <b>-g</b> flags are not mutually exclusive.

<p><b>offset</b> and <b>scale</b> modify color rules to match the
values of a raster map using the formula <em>new_value = (old_value +
offset) x scale</em>. For example, if the units of a raster map are
Kelvin x 50, the color rules <em>celsius</em> can be applied with
<em>offset=273.15</em> and <em>scale=50</em>.


<p>If the user specifies the <b>-w</b> flag, the current color table file for
the input map will not be overwritten. This means that the color table is
created only if the <i>map</i> does not already have a color table. If this
option is not specified, the color table will be created if one does not
exist, or modified if it does.

<p><p>Color table types <i>aspect, grey, grey.eq</i> (histogram-equalized
grey scale), <i>byg</i> (blue-yellow-green), <i>byr</i>
(blue-yellow-red), <i>gyr</i> (green-yellow-red), <i>rainbow, ramp,
ryg</i> (red-yellow-green), <i>random</i>, and <i>wave</i> are
pre-defined color tables that <em>r.colors</em> knows how to create
without any further input.

<p>
In case several input raster maps are provided the range (min, max) of all maps 
will be used for color table creation. Hence the created color table will span from
the smallest minimum to the largest maximum value of all input raster maps and
will be applied to all input raster maps.

<p>In general, tables which associate colors with percentages (aspect, bcyr, byg,
byr, elevation, grey, gyr, rainbow, ramp, ryb, ryg and wave) can be applied to
any data, while those which use absolute values (aspectcolr, curvature, etopo2,
evi, ndvi, population, slope, srtm, and terrain) only make sense for data with
certain ranges.

One can get a rough idea of the applicability of a colour table by reading the
corresponding rules file (<tt>$GISBASE/etc/colors/&lt;name&gt;</tt>).
For example the <em>slope</em> rule is defined as:

<div class="code"><pre>
0  255:255:255
2  255:255:0
5  0:255:0
10 0:255 255
15 0:0:255
30 255:0:255
50 255:0:0
90 0:0:0
</pre></div>

<p>This is designed for the slope map generated
by <em><a href="r.slope.aspect.html">r.slope.aspect</a></em>, where the
value is a slope angle between 0 and 90 degrees.

<p>Similarly, the <em>aspectcolr</em> rule:

<div class="code"><pre>
0 white
1 yellow
90 green
180 cyan
270 red
360 yellow
</pre></div>

<p>is designed for the aspect maps produced
by <em><a href="r.slope.aspect.html">r.slope.aspect</a></em>, where the
value is a heading between 0 and 360 degrees.

<p>The <b>rules</b> color table type will cause <i>r.colors</i> to read
color table specifications from standard input (stdin) and will build
the color table accordingly.

<p>Using color table type <b>rules</b>, there are <!--three-->two ways to
build a color table: <!--by color list,--> by category values and by
&quot;percent&quot; values.

<!-- HB: this causes an error in current code, maybe easy to enable functionality from old code??
<p>Building a customized color table by color list is the simplest of the three
rules methods: just list the colors you wish to appear in the color table in the
order that you wish them to appear. Use the standard GRASS color names: white,
black, red, green, blue, yellow, magenta, cyan, aqua, grey, gray, orange, brown,
purple, violet, and indigo.

<p>For example, to create a color table for the raster map layer <i>elevation</i>
that assigns greens to low map category values, browns to the next larger
map category values, and yellows to the still larger map category values,
one would type:

<div class="code"><pre>
<b>r.colors map=</b><i>elevation</i> <b>color=</b><i>rules</i>
green
brown
yellow
end
</pre></div>
-->
<p>To build a color table by category values' indices, the user should
determine the range of category values in the raster map with which
the color table will be used. Specific category values will then be
associated with specific colors. Note that a color does not have to be
assigned for every valid category value because <em>r.colors</em> will
interpolate a color ramp to fill in where color specification rules
have been left out. The format of such a specification is as follows:

<div class="code"><pre>
category_value color_name
category_value color_name
.. ..
.. ..
category_value color_name
end
</pre></div>

<p>Each category value must be valid for the raster map, category values
must be in ascending order and only use standard GRASS color names
(aqua, black, blue, brown, cyan, gray, green, grey, indigo, magenta,
orange, purple, red, violet, white, yellow).

<p>Colors can also be specified by color numbers each in the range
0-255. The format of a category value color table specification using
color numbers instead of color names is as follows:

<div class="code"><pre>
category_value red_number:green_number:blue_number
category_value red_number:green_number:blue_number
.. .. .. ..
.. .. .. ..
category_value red_number:green_number:blue_number
end
</pre></div>

<p>Specifying a color table by &quot;percent&quot; values allows one to
treat a color table as if it were numbered from 0 to 100. The format
of a &quot;percent&quot; value color table specification is the same
as for a category value color specification, except that the category
values are replaced by &quot;percent&quot; values, each from 0-100, in
ascending order. The format is as follows:

<div class="code"><pre>
percent_value% color_name
percent_value% color_name
.. ..
.. ..
percent_value% color_name
end
</pre></div>

<p>Using &quot;percent&quot; value color table specification rules,
colors can also be specified by color numbers each in the range
0-255. The format of a percent value color table specification using
color numbers instead of color names is as follows:

<div class="code"><pre>
percent_value% red_number:green_number:blue_number
percent_value% red_number:green_number:blue_number
.. .. .. ..
.. .. .. ..
percent_value% red_number:green_number:blue_number
end
</pre></div>

<p>Note that you can also mix these <!--three-->two methods of color
table specification; for example:

<div class="code"><pre>
0 black
10% yellow
78 blue<!--\n magenta
purple
brown-->
100% 0:255:230
end
</pre></div>

<p>To set the NULL (no data) color, use the "nv" (null values) parameter:

<div class="code"><pre>
0 black
10% yellow
nv white
end
</pre></div>

<p>To set the color to used for undefined values (beyond the range of the
color rules) use the "default" parameter:

<div class="code"><pre>
0 red
1 blue
default grey
end
</pre></div>

<h2>NOTES</h2>

All color tables are stored in <tt>$GISBASE/etc/colors/</tt>. Further
user-defined color tables can also be stored in this directory for
access from the <em>color</em> parameter or in a user defined directory.
See also <em>r.colors.out</em> for printing color tables easily to the
terminal.
<p>
The color table assigned to a raster map is stored in
<tt>$GISDBASE/location/mapset/colr/</tt>.

<h2>EXAMPLES</h2>

The below example shows how you can specify colors for a three
category map, assigning red to category 1, green to category 2, and
blue to category 3. Start by using a text editor to create the
following rules specification file (save it with the
name <i>rules.file</i>):

<div class="code"><pre>
1 red
2 green
3 blue
end
</pre></div>

<p>The color table can then by assigned to map <i>threecats</i> by the
following GRASS commands (two ways are available):

<div class="code"><pre>
# read input from stdin
cat rules.file | r.colors map=threecats rules=-

# read directly from file
r.colors map=threecats rules=rules.file
</pre></div>

<p>To create a natural looking lookup table (LUT) for true map layer
<i>elevation</i>, use the following rules specification file. It will
assign light green shades to the lower elevations (first 20% of the
LUT), and then darker greens (next 15%, and next 20%) and light browns
(next 20%) for middle elevations, and darker browns (next 15%) for
higher elevations, and finally yellow for the highest peaks (last 10%
of LUT).

<div class="code"><pre>
0% 0:230:0
20% 0:160:0
35% 50:130:0
55% 120:100:30
75% 120:130:40
90% 170:160:50
100% 255:255:100
</pre></div>

<p>To invert the current rules: 
<div class="code"><pre>
r.colors map=current_raster -n rast=current_raster
</pre></div>

<h2>SEE ALSO</h2>

<em>
  <a href="d.colortable.html">d.colortable</a>,
  <a href="d.histogram.html">d.histogram</a>,
  <a href="d.legend.html">d.legend</a>,
  <a href="r.colors.out.html">r.colors.out</a>
  <a href="r.colors.stddev.html">r.colors.stddev</a>,
  <a href="r.support.html">r.support</a>,
  <a href="r.univar.html">r.univar</a>,
  <a href="v.colors.html">v.colors</a>,
  <a href="v.colors.out.html">v.colors.out</a>,
  <a href="r3.colors.html">r3.colors</a>,
  <a href="r3.colors.out.html">r3.colors.out</a>
</em>

<p>See also wiki
page <a href="https://grasswiki.osgeo.org/wiki/Color_tables">Color
tables</a> (from GRASS User Wiki)

<p><a href="http://colorbrewer.org">ColorBrewer</a> is an online tool designed to
help people select good color schemes for maps and other graphics.


<h2>AUTHORS</h2>
Michael Shapiro and David Johnson<br>
Support for 3D rasters by Soeren Gebbert

<!--
<p>
<i>Last changed: $Date$</i>
-->
